package com.example.ceshi.utils;

import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import com.example.ceshi.Bean.BrandDetail;
import com.example.ceshi.Bean.DetailBean;
import com.example.ceshi.Bean.NowUserData;
import com.google.gson.Gson;

import org.apache.log4j.BasicConfigurator;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.Objects;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.BufferedSink;

public class NetUtil {
    private static final String TAG = "ning";
    private static final String TAG2 = "ming";
    private static String result = "";
    //    private static String number;
    private static String result_brand = "";


    private static  OkHttpClient client = new OkHttpClient();



    public static String getDetails(String number) {
        String url="https://jmexpressv2.api.bdymkt.com/express/query-v2?number="+number;

        FormBody formBody = new FormBody.Builder()
                .build();
//        Log.d(TAG2,"执行前");
        Request request = new Request.Builder()
                .url(url)
                .post(formBody)
                .addHeader("X-Bce-Signature","AppCode/5158a479eaa141f18f0a506c974df7be")
                .build();
//        Log.d(TAG2,"执行后");
//        Call call = client.newCall(request);
//            result=request.body().toString();

//        call.enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
////                Toast.makeText(OkHttpActivity.this, "Post Failed", Toast.LENGTH_SHORT).show();
//                Log.d(TAG2,"数据请求失败");
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//                final String res = response.body().string();
//                result=res;
//            }
//        });

        try {
            Response response=client.newCall(request).execute();
            result=response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result;

    }


    public static String getBrand(String number) {
        String url = "https://jmexpressv2.api.bdymkt.com/express/number-discern"+number;

        FormBody formBody = new FormBody.Builder()
                .build();
//        Log.d(TAG2,"执行前");
        Request request = new Request.Builder()
                .url(url)
                .post(formBody)
                .addHeader("X-Bce-Signature","AppCode/5158a479eaa141f18f0a506c974df7be")
                .build();

        try {
            Response response=client.newCall(request).execute();
            result_brand=response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result_brand;
    }



}
